import com.work.entity.Weather;
import com.work.service.impl.WeatherServiceImpl;
import com.work.utils.DbUtil;
import org.hibernate.*;
import org.hibernate.criterion.Restrictions;
import org.hibernate.query.Query;
import org.hibernate.cfg.Configuration;

import javax.persistence.metamodel.EntityType;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by baichenguang on 2020/2/18.
 */
public class Main {
    private static final SessionFactory ourSessionFactory;

    static {
        try {
            Configuration configuration = new Configuration();
            configuration.configure();

            ourSessionFactory = configuration.buildSessionFactory();
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session getSession() throws HibernateException {
        return ourSessionFactory.openSession();
    }

    public static void main(final String[] args) throws Exception {
        final Session session = getSession();
        List<Weather> weathers = new ArrayList<Weather>();
        WeatherServiceImpl weatherService = new WeatherServiceImpl();
        try{
            String startStr = "2020/2/8 00:00:00";
            String endStr = "2020/2/8 23:59:59";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            Date start = sdf.parse(startStr);
            Date end = sdf.parse(endStr);
            weathers = weatherService.getWeatherListByDate(start,end);


        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
    }

}